package com.example.demomk.Adapter;



import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.example.demomk.Utils.StatRow;
import com.example.demomk.databinding.ItemConutBinding;

import java.util.ArrayList;
import java.util.List;

public class CountAdapter extends RecyclerView.Adapter<CountAdapter.ViewHolder> {
    private List<String> mAllCounts;
    private List<StatRow> rows = new ArrayList<>();
    @NonNull
    @Override
    public CountAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemConutBinding binding = ItemConutBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull CountAdapter.ViewHolder holder, int position) {
//        String item = mAllCounts.get(position);
//        holder.index.setText(item);
        StatRow row = rows.get(position);
        holder.index.setText(row.label);
        holder.avg05.setText(String.valueOf(row.value05));
        holder.avg10.setText(String.valueOf(row.value10));
        holder.avg20.setText(String.valueOf(row.value20));
        holder.avg30.setText(String.valueOf(row.value30));
        holder.avg50.setText(String.valueOf(row.value50));
        holder.avg100.setText(String.valueOf(row.value100));
    }

    @Override
    public int getItemCount() {
        return rows.size();
    }
    public void setAllCounts(List<String> allCounts) {
        mAllCounts = allCounts;
        notifyDataSetChanged();
    }

    public void submitList(List<StatRow> list) {
        rows.clear();
        rows.addAll(list);
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView index, avg05, avg10, avg20, avg30, avg50, avg100;
        public ViewHolder(@NonNull ItemConutBinding binding) {
            super(binding.getRoot());
            index = binding.index;
            avg05 = binding.avgZerofive;
            avg10 = binding.avgOne;
            avg20 = binding.avgTwo;
            avg30 = binding.avgThere;
            avg50 = binding.avgFive;
            avg100 = binding.avgTen;
        }
    }
}
